import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
// import app from './modules/app'
// console.log(app, 'app')
// import settings from './modules/settings'
// import user from './modules/user'

// require.context('导入文件的目录','是否递归获取','正则规则匹配指定的文件')

const req = require.context('./modules', false, /\.js$/)
console.log(req.keys(), 'req.keys()') // ['./app.js', './settings.js', './user.js']
// 获取所有文件的名称
const mName = req.keys().map(item => item.split('./')[1]).map(item => item.split('.js')[0])
console.log(mName, 'mName')

console.log(req.keys().map(item => req(item)), 'map')
// 批量导入制定目录下的文件对象，存入到一个数组中
const mObj = req.keys().map(item => req(item))

const obj = {}
// 组装成js对象： {文件名: 模块对象}
mName.forEach((key, index) => {
  console.log(key, 'mName')
  obj[key] = mObj[index].default
})

console.log(obj, 'obj')

Vue.use(Vuex)

const store = new Vuex.Store({
  modules: obj,
  getters
})

export default store
